package com.wze.wze.Controller;

import com.wze.wze.Aop.PasToken;
import com.wze.wze.Entity.LikeMusic;
import com.wze.wze.Entity.ResultEntity;
import com.wze.wze.Entity.v_gz;
import com.wze.wze.Entity.v_pl;
import com.wze.wze.Service.VgzService;
import com.wze.wze.Util.JSONTool;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域
@RestController //控制器注解
@RequestMapping("/vGz/")//请求路径
public class V_gzController {
    @Resource
    VgzService vgzService;
    ResultEntity resultEntity = null;

    @PasToken
    @GetMapping("GzList")
    private String PlList(
            @RequestParam("page") int page,
            @RequestParam("limit") int limit,
            @RequestParam("id")  int id,
            @RequestParam("Uid")  int Uid
    ){
        try {
            resultEntity = new ResultEntity();
            int Start = (page-1) * limit;//计算分页位置
            List<v_gz> list = vgzService.getGZList(Start, limit, id, Uid);
            if(id!=-1 || Uid!=-1){//有条件
                resultEntity.setCount(String.valueOf(list.size()));
            }else {//没有查询条件
                resultEntity.setCount(String.valueOf(vgzService.getGzCount()));
            }
            resultEntity.setCode("0");
            resultEntity.setData(list);
            resultEntity.setMsg("查询成功!");
        }catch (Exception e){
            resultEntity.setCode("1");
            resultEntity.setMsg("查询失败!"+e.getMessage());
        }
        return JSONTool.getJsonTool().toJson(resultEntity);
    }


    @GetMapping("GZ")
    private String getUserById(@RequestParam("Uid") int Uid,@RequestParam("Sid") int Sid) {
        resultEntity = new ResultEntity();
        try {
            v_gz vgz = vgzService.getGZById(Uid, Sid);
            if (vgz == null) {
                resultEntity.setCode("1");
                resultEntity.setMsg("查无此人");
            } else {
                resultEntity.setCode("0");
                resultEntity.setMsg("查询成功");
                resultEntity.setData(vgz);
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultEntity.setCode("9999");
            resultEntity.setMsg("系统错误，请联系管理员");
        }
        return JSONTool.getJsonTool().toJson(resultEntity);

    }
}
